(ns blade-art-online.core.skill-logic-test
 (:require [clojure.test :refer :all]
           [blade-art-online.core.skill-logic :refer :all]
           [blade-art-online.core.skills :refer [buffs damage skills spawn-effect]]))


(deftest test-buffs-process
 (is
  (= 4
     (buffs-process :test [{:test #(+ 1 %)} {:test #(+ 2 %)}] 1))
  "等于4")
 (is
  (= 3
     (buffs-process :test [{:test #(do %)} {:test #(+ 2 %)}] 1))
  "等于3"))

(deftest test-buffkeys-to-buffs
 (is
  (= [(:poison buffs) (:once-shield buffs)]
     (buffkeys-to-buffs [:poison :once-shield]))))

(deftest test-produce-effect
 (let [skill {:produce-effect (fn [_] 2)}
       all {:name 1}]
      (is
       (= {:name 1 :effect 2}
          (produce-effect skill all)))))

(deftest test-real-damage
 (is
  (= 2
     (real-damage 10 12))
  (= 1
     (real-damage 10 5))))

(deftest test-damage-on-tar
 (let [damage 20
       tar {:hp 100 :def 10}]
      (is
       (= (assoc tar :hp 90)
          (damage-on-tar damage tar)))))

(deftest test-use-skill
 ; 测试使用垂直四方斩
 (is
  (let [kirito {:str 10}
       monster {:hp 100 :def 0}]
       (= {:src kirito :tar (damage 15 monster)}
          (use-skill :skill-key :vertical-chop :src kirito :tar monster))))
 (is
  (let [kirito {:str 100}
        monster {:hp 100 :def 10}]
       (= {:src kirito :tar (damage 50 monster)}
          (use-skill :skill-key :vertical-chop :src kirito :tar monster))))
 (is
  (let [kirito {:str 10}
        monster {:hp 0 :def 20}]
       (= {:src kirito :tar (damage 1 monster)}
          (use-skill :skill-key :vertical-chop :src kirito :tar monster))))
  ; 测试使用寒冰屏障
  (is
  (let [kirito nil 
        monster (life-spawn)]
       (= {:src kirito :tar (assoc monster :buffkeys [:once-shield])}
          (use-skill :skill-key :once-shield :src kirito :tar monster)))))